from time import time

def getLength1(n: int) -> int:
    s = ""
    for i in range(1, n + 1):
        s += str(i)
    return len(s)

def getLength2(n: int) -> int:
    totalLength = 0
    for i in range(1, n + 1):
        p, len = i, 1
        while p >= 10:
            p //= 10
            len += 1
        totalLength += len
    return totalLength

def getLength3(n: int) -> int:
    totalLength, b = 0, 1
    while n >= b:
        totalLength += n - b + 1
        b *= 10
    return totalLength

n = 20000000
#99999999999999999999999999999999999999999999999
T = time()
totalLength = getLength2(n)
T = time() - T
print('N=', n, '\n总长度为', totalLength)
print('运行时间', T, '秒')